<?
if (!defined('MODULE_FILE')){
die ("cant access file directly!");
}

$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );

autoLoader();

$objBaseTemplateMaster 	= new BaseTemplateMaster();
$objTemplateMaster 		= new TemplateMaster();
?>
<html>
<head>
<?php require_once 'commonJS.php'; ?>
</head>
<body>
</br>
<div style="margin-left:12px;">
<p>
	<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=view_templates_master&type=view&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >View All Tempaltes</a>&nbsp;
	<a class="btn btn-outline btn-primary btn-xs" id="act" href="modules.php?file=templates_master&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >Add Templates</a>
</p> 
</div>

<div class="col-lg-8">
<div class="panel panel-primary">
<div class="panel-heading"><i class="fa fa-bell fa-fw"></i>Add New Templates</div>
<div class="panel-body">
<form METHOD="POST" action="modules.php?file=insert_templates_master&type=insert&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>" id="formSubmit" name="formSubmit" >
	<?php
	$intTemplateMasterId = NULL;
	$strName = NULL;
	$strDescription = NULL;
	$strData = NULL;
	$intTemplateTypeId = NULL;
	
	if( true == isset( $_GET['temp_master_id'] ) && true == valStr( $_GET['temp_master_id'] ) ) {
		$intTemplateMasterId = $_GET['temp_master_id'];
		
		$objBaseTemplateMaster = $objTemplateMaster->fetchTemplateMasterById( $_GET['temp_master_id'] );
		
		if( true == valObj( $objBaseTemplateMaster, 'BaseTemplateMaster' ) ) {
			$strName 				= $objBaseTemplateMaster->getName();
			$strDescription 		= $objBaseTemplateMaster->getDescription();
			$strData 		        = $objBaseTemplateMaster->getData();
			$intTemplateTypeId 		= $objBaseTemplateMaster->getTemplateTypeId();
		}
	} else if( true == valObj( $objBaseTemplateMaster, 'BaseTemplateMaster' ) ) {
		$intTemplateMasterId = $objBaseTemplateMaster->fetchNextId();
	}
	?>
	
		<table width="90%" cellspacing="0" cellpadding="3">
			
			<tr><td height="10" colspan="2">
			<input type="hidden" id="temp_master_id" name="temp_master_id" value="<?php echo $intTemplateMasterId?>"></td></tr>
            <tr valign="top">
				<td class="mandatory" width="170">Template Type</td>
				<td>
				<select class="validate[required]" name="temp_type_id" id="temp_type_id" style="width:202px;"  >
				<option value=''>-Select-</option>
				<option value='1' <?php echo ( ( 1 == $intTemplateTypeId ) ? 'selected' : '' ); ?>>Cheif Complaints</option>
				<option value='2' <?php echo ( ( 2 == $intTemplateTypeId ) ? 'selected' : '' ); ?>>Prescription</option>
				<option value='3' <?php echo ( ( 3 == $intTemplateTypeId ) ? 'selected' : '' ); ?>>Diagnosis</option>
				<option value='4' <?php echo ( ( 4 == $intTemplateTypeId ) ? 'selected' : '' ); ?>>Investigation</option>
				</select>
				</td>
			</tr>
         	<tr>
				<td colspan="2" height="15px"></td>
			</tr>
			<tr valign="top">
				<td  width="170">Name</td>
				<td><input class="validate[required]" type="text" name="name" id="name" value="<?php echo $strName?>" style="width:202px;">
		        </td>
			</tr>
			<tr><td colspan="2" height="10px"></td></tr>
         	<tr>	
			 <td width="170">Description</td>				
		      <td><textarea  class="form-control" name="description" rows="3" cols="70" ><?php echo $strDescription?></textarea></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td class="mandatory" width="170">Details</td>
				 <td><textarea  name="message" class="form-control" rows="3" cols="70" ><?php echo $strData?></textarea></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td class="mandatory" width="170">&nbsp;</td>
				<td>
				<?php
					if( true == isset( $_GET['temp_master_id'] ) && true == valStr( $_GET['temp_master_id'] ) ) {
						echo "<input type=hidden name=operation value=update>";
						echo "<input type=submit value=UPDATE id=Submit name=Submit>";
					} else {
						echo "<input type=hidden name=operation value=insert>";
						echo "<input type=submit value=SUBMIT id=Submit name=Submit>";
					}
					?>
				</td> 				
			</tr>
		</table>
	
</form>
</div>
</div>
</div>
</body>
</html>